// Node.cpp : Implementation of CNode

#include "stdafx.h"
#include "Node.h"
#include "Nodes.h"

#pragma warning(disable : 4996)
// CNode

STDMETHODIMP CNode::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&IID_INode
	};

	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}

STDMETHODIMP CNode::get_Id(LONG* pVal)
{	
	*pVal = m_id;
	return S_OK;
}

STDMETHODIMP CNode::get_Name(BSTR* pVal)
{
	*pVal = m_name;
	return S_OK;
}

STDMETHODIMP CNode::get_Parent(INode** pVal)
{
	
//
//	_variant_t id = m_spRS->Fields->Item["ParentId"];
//	if (id.vt = VT_NULL)	//root
//	{
//		*pVal = NULL;
//		return S_OK;
//	}
//
//	long parentId = id;
//
//	_RecordsetPtr spRS;
//	WCHAR strParentId[20];
//	_ltow(parentId, strParentId, 10);
//	
////	CDBHelper::GetInstance().ExecuteText(_bstr_t(L"SELECT TOP 1 * FROM Feature WHERE Id=") + strParentId, spRS);
//	CDBHelper::GetInstance().ExecuteText(_bstr_t(L"SELECT TOP 1 * FROM Feature WHERE Id=") + strParentId, spRS);
//	spRS.AddRef();
//	CComObject<CNode> * pNode;
//	pNode->CreateInstance(&pNode);
//	pNode->SetRecordset(spRS);
//	pNode->AddRef();
//	*pVal = pNode;
	return S_OK;
}

STDMETHODIMP CNode::get_Nodes(INodes** pVal)
{
	//long id;
	//this->get_Id(&id);
	//_RecordsetPtr spRS;
	//WCHAR strParentId[20];
	//_ltow(id, strParentId, 10);
	//_bstr_t sql(L"SELECT * FROM Feature WHERE ParentId=");
	//sql += strParentId;
	//CDBHelper::GetInstance().ExecuteText(sql, spRS);
	//spRS.AddRef();
	//
	//CComObject<CNodes> * pNodes;
	//pNodes->CreateInstance(&pNodes);
	//pNodes->SetRecordset(spRS);
	//pNodes->AddRef();
	//*pVal = pNodes;
	return S_OK;
}


HRESULT CNode::Init(CDatastore* pDs, int id)
{
	m_pDs = pDs;
	
	//m_pDs->m_pDBHelper->ExecuteText(L"SELECT TOP 1 * from Node WHERE Id=
	return E_NOTIMPL;
}
